﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using VIBlend.WPF.Controls;

namespace AnonsaiWPF.CSharp
{
    /// <summary>
    /// Interaction logic for MaskInputEditor.xaml
    /// </summary>
    public partial class MaskInputEditor : Window, IWindow
    {
        public void DetachContent()
        {
            RemoveLogicalChild(Content);
        }

        public void SetTheme()
        {
        }
  
        public Grid Root
        {
            get
            {
                return this.RootVisual;
            }
        }

        public MaskInputEditor()
        {
            InitializeComponent();
            this.Numeric.ValueChanging += new EventHandler<System.ComponentModel.CancelEventArgs>(Numeric_ValueChanging);
            this.Numeric.ValueChanged += new EventHandler(Numeric_ValueChanged);

            this.Phone.ValueChanging += new EventHandler<System.ComponentModel.CancelEventArgs>(Numeric_ValueChanging);
            this.Phone.ValueChanged += new EventHandler(Numeric_ValueChanged);

            this.SSN.ValueChanging += new EventHandler<System.ComponentModel.CancelEventArgs>(Numeric_ValueChanging);
            this.SSN.ValueChanged += new EventHandler(Numeric_ValueChanged);

            this.Date.ValueChanging += new EventHandler<System.ComponentModel.CancelEventArgs>(Numeric_ValueChanging);
            this.Date.ValueChanged += new EventHandler(Numeric_ValueChanged);

            this.DateTime.ValueChanging += new EventHandler<System.ComponentModel.CancelEventArgs>(Numeric_ValueChanging);
            this.DateTime.ValueChanged += new EventHandler(Numeric_ValueChanged);

            this.Zip.ValueChanging += new EventHandler<System.ComponentModel.CancelEventArgs>(Numeric_ValueChanging);
            this.Zip.ValueChanged += new EventHandler(Numeric_ValueChanged);

            this.TIMEEU.ValueChanging += new EventHandler<System.ComponentModel.CancelEventArgs>(Numeric_ValueChanging);
            this.TIMEEU.ValueChanged += new EventHandler(Numeric_ValueChanged);

            this.TIMEUS.ValueChanging += new EventHandler<System.ComponentModel.CancelEventArgs>(Numeric_ValueChanging);
            this.TIMEUS.ValueChanged += new EventHandler(Numeric_ValueChanged);
           
        }

        void Numeric_ValueChanged(object sender, EventArgs e)
        {
            MaskEditor input = sender as MaskEditor;
            this.Events.Items.Add("ValueChanged: " + input.Value);       
        }

        void Numeric_ValueChanging(object sender, System.ComponentModel.CancelEventArgs e)
        {
            MaskEditor input = sender as MaskEditor;
            this.Events.Items.Clear();
            this.Events.Items.Add("ValueChanging: " + "\nNew:" + input.Value + "\nOld:" + input.LastValue);       
        }

        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            switch (this.Prompt.SelectedIndex)
            {
                case 0:
                    SetPromptChar('_');
                    break;
                case 1:
                    SetPromptChar('?');
                    break;
                case 2:
                    SetPromptChar('^');
                    break;
                case 3:
                    SetPromptChar('*');
                    break;
                case 4:
                    SetPromptChar('+');
                    break;
            }
        }

        private void SetPromptChar(char promptChar)
        {
            this.Numeric.PromptChar = promptChar;
            this.Phone.PromptChar = promptChar;
            this.DateTime.PromptChar = promptChar;
            this.Date.PromptChar = promptChar;
            this.TIMEUS.PromptChar = promptChar;
            this.TIMEEU.PromptChar = promptChar;
            this.Zip.PromptChar = promptChar;
            this.SSN.PromptChar = promptChar; 
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            this.Numeric.Value = null;
            this.Phone.Value = null;
            this.DateTime.Value = null;
            this.Date.Value = null;
            this.TIMEUS.Value = null;
            this.TIMEEU.Value = null;
            this.Zip.Value = null;
            this.SSN.Value = null;
        }
    
    }
}
